package org.example.d2_collections;

import java.util.*;

public class CollectionsTest1 {
    public static void main(String[] args) {
        //1,public static<T> boolean addAll(collection<? super T>c,T...elements):为集合批量添加数据
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三", "李四", "王五", "赵六");
        System.out.println(names);
// 2、public static void shuffle(List<?> list):打乱List集合中的元素顺序
        Collections.shuffle(names);
        System.out.println(names);
//3、public static <T> void sort(List <T> list):wList集合中的元紧进行升序指序。
        List<Integer> list = new ArrayList<>();
        list.add(8);
        list.add(4);
        list.add(6);
        list.add(2);
        Collections.sort(list);
        System.out.println(list);

        List<Student> students = new ArrayList<>();
        students.add(new Student("蜘蛛精", 23, 169.7));
        students.add(new Student("紫霞", 22, 168.7));
        students.add(new Student("紫霞", 22, 168.7));
        students.add(new Student("至尊宝", 26, 165.7));
        Collections.sort(students);//报错，因为类型不一样 不知道按照什么规则进行排序
        System.out.println(students);


// 4. public static <T> void sort(List<T>list, Comparator? super T>c):对list集分中元素,按照比较器对象攒定的规燜进
        //定义一个比较器对象
        Collections.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o1.getHeight(),o2.getHeight());
            }
        });
    }
}

